<?php

namespace IDock\Insurance\CHAC\Response;

use IDock\Http\Response;
use IDock\Printer\EPolicyDownloadPrinter;

class HEPolicyDownloadResponse extends AllCHACResponse
{

    /*** @var EPolicyDownloadPrinter $printer */
    public $printer = EPolicyDownloadPrinter::class;

    public $urlDecode = true;

    public $biUrl;

    public $ciUrl;

    public function printerInit(): Response
    {
        $header = $this->get('responseHead');

        if ($header['responseCode'] != '0000') {
            $this->setError($header['errorMessage'] ?? '');
            return $this;
        }

        $responseBody = $this->get('responseBody', []);

        $electronicPolicy = $responseBody['electronicPolicy'] ?? [];

        $this->biUrl = $electronicPolicy['biDownLoad'] ?? '';
        $this->ciUrl = $electronicPolicy['ciDownLoad'] ?? '';

        return $this;
    }
}
